package com.yy.jhl.ui.manager.presenter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yy.common.commonutils.StringUtil;
import com.yy.jhl.api.Api;
import com.yy.jhl.api.RxSubscriber;
import com.yy.jhl.bean.InviteUploadInfo;
import com.yy.jhl.ui.manager.contract.InviteUploadContract;
import com.yy.jhl.ui.manager.contract.UploadHistoryContract;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import rx.Observable;

/**
 * Created by libingn on 2017/12/18.
 */

public class UploadHistoryPresenter extends UploadHistoryContract.Presenter {


    @Override
    public void getHistoryInfo(boolean isShowDialog) {
        mRxManage.addSubscription(Api.getDefault().getUploadHistory(), new RxSubscriber<ResponseBody>(mContext,isShowDialog) {
            @Override
            protected void _onNext(String result) {
                Gson gson=new Gson();
                List<InviteUploadInfo> rs=new ArrayList<InviteUploadInfo>();
                Type type = new TypeToken<ArrayList<InviteUploadInfo>>() {}.getType();
                rs=gson.fromJson(result, type);
                mView.getHistoryInfoSuccess(rs);
            }

            @Override
            protected void _onError(String message) {
                mView.getHistoryInfoFail();
            }
        });
    }

    @Override
    public void checkInfo() {
        RequestBody requestBody = new FormBody.Builder()
            .build();
        mRxManage.addSubscription(Api.getDefault().checkInfo(requestBody), new RxSubscriber<ResponseBody>(mContext,true) {
            @Override
            protected void _onNext(String result) {
                mView.getCheckInfo(true);
            }

            @Override
            protected void _onError(String message) {
                mView.getCheckInfo(false);
            }
        });
    }
}
